package com.github.dongglin.smart.spring.boot.plus.common.exception;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class BadArgumentException extends RuntimeException {

    /**
     *
     */
    private static final long serialVersionUID = 8959903977235515617L;

    private Map<String, Object> exception;

    /**
     * 构造异常
     *
     * @param exception 异常信息
     */
    public BadArgumentException(Map<String, Object> exception) {
        this.exception = null == exception ? Collections.emptyMap() : exception;
    }

    /**
     * 构造异常
     *
     * @param exceptions 异常集合
     */
    public BadArgumentException(List<Map<String, Object>> exceptions) {
        if (null != exceptions && !exceptions.isEmpty()) {
            Map<String, Object> exceptioneMap = new LinkedHashMap<>();
            exceptions.stream().forEach(item -> exceptioneMap.putAll(item));
            this.exception = exceptioneMap;
        } else {
            this.exception = Collections.emptyMap();
        }
    }

    /**
     * 获取异常
     *
     * @return map
     */
    public Map<String, Object> getExceptionMap() {
        return exception;
    }
}
